package br.com.sgpv2.entity.usuario;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "usu_usuario")
@SequenceGenerator(name = "sequenceUsuario", sequenceName = "usu_usuario_usu_id_seq")
public class Usuario implements Serializable {
	
	private int id;
	private String login;
	private String senha;
	private TipoUsuarioEnum tipoUsuario;
	private boolean isAdmin;
	
	/**
	* Recupera o id da entidade.
	*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "sec_id", nullable = false)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="usu_login")
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	
	@Column(name="usu_senha")
	public String getSenha() {
		return senha;
	}
	public void setSenha(String senha) {
		this.senha = senha;
	}
	
	@Transient
	public boolean getIsAdmin() {
		boolean isAdmin = false;
		if(TipoUsuarioEnum.ADMIN.equals(this.tipoUsuario)){
			isAdmin = true;
		}
		return isAdmin;
	}
	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	@Column(name = "usu_tipo")
	@Enumerated(EnumType.STRING)
	public TipoUsuarioEnum getTipoUsuario() {
		return tipoUsuario;
	}
	public void setTipoUsuario(TipoUsuarioEnum tipoUsuario) {
		this.tipoUsuario = tipoUsuario;
	}
	

}
